package com.sljy.hzk.ui.task;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.sljy.hzk.R;
import com.sljy.hzk.animation.AnimationManager;
import com.sljy.hzk.annotation.ActivityInfo;
import com.sljy.hzk.base.BaseActivity;
import com.sljy.hzk.util.EventListenerManager;
import com.sljy.hzk.util.TimeUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;

@ActivityInfo(layout = R.layout.activity_date, isShowActionBar = true, title = "",rightIcRes = R.drawable.homepage)
public class Task_DateActivity extends BaseActivity {

    @BindView(R.id.todayBtn)
    Button todayBtn;
    @BindView(R.id.centerBtn)
    ImageButton centerBtn;
    @BindView(R.id.timeText1)
    TextView timeText1;
    @BindView(R.id.timeText2)
    TextView timeText2;
    @BindView(R.id.timeText3)
    TextView timeText3;
    @BindView(R.id.timeText4)
    TextView timeText4;
    @BindView(R.id.timeText5)
    TextView timeText5;
    @BindView(R.id.timeText6)
    TextView timeText6;
    @BindView(R.id.timeText7)
    TextView timeText7;
    @BindView(R.id.timeText8)
    TextView timeText8;
    @BindView(R.id.timeText9)
    TextView timeText9;
    @BindView(R.id.timeText10)
    TextView timeText10;
    @BindView(R.id.timeText11)
    TextView timeText11;
    @BindView(R.id.timeText12)
    TextView timeText12;
    @BindView(R.id.timeText13)
    TextView timeText13;
    @BindView(R.id.timeText14)
    TextView timeText14;
    @BindView(R.id.curTime)
    TextView curTime;
    Date nowDate;
    @Override
    protected void init() {
        nowDate = TimeUtils.getNowDate();
        Intent intent = getIntent();
        String mdate = intent.getStringExtra("nowDate");
        curTime.setText(mdate.replace("-","."));
        curTime.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                try {
                    EventListenerManager.Instance().sendEvent("TimeChoiseCallBack",curTime.getText().toString().replace(".","-"));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                finish();
            }
        });
        todayBtn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                curTime.setText(TimeUtils.dateToStr(nowDate));
            }
        });
        initWeekDate();
        onClick(timeText1);
        onClick(timeText2);
        onClick(timeText3);
        onClick(timeText4);
        onClick(timeText5);
        onClick(timeText6);
        onClick(timeText7);
        onClick(timeText8);
        onClick(timeText9);
        onClick(timeText10);
        onClick(timeText11);
        onClick(timeText12);
        onClick(timeText13);
        onClick(timeText14);
    }

    private String getDate(String date){
        String s1 = date.substring(0,4)+".";
        String s2 = date.substring(5,10);
        date = s1+s2;
        return date;
    }


    /**
     * 加载前后一周
     * */
    private void initWeekDate(){
        List<Date> list = TimeUtils.getBeforeWeek(nowDate);
        timeText7.setText(TimeUtils.dateToStr(list.get(6),"."));
        timeText6.setText(TimeUtils.dateToStr(list.get(5),"."));
        timeText5.setText(TimeUtils.dateToStr(list.get(4),"."));
        timeText4.setText(TimeUtils.dateToStr(list.get(3),"."));
        timeText3.setText(TimeUtils.dateToStr(list.get(2),"."));
        timeText2.setText(TimeUtils.dateToStr(list.get(1),"."));
        timeText1.setText(TimeUtils.dateToStr(list.get(0),"."));
        list = TimeUtils.getTomorrowWeek(nowDate);
        timeText8.setText(TimeUtils.dateToStr(list.get(0),"."));
        timeText9.setText(TimeUtils.dateToStr(list.get(1),"."));
        timeText10.setText(TimeUtils.dateToStr(list.get(2),"."));
        timeText11.setText(TimeUtils.dateToStr(list.get(3),"."));
        timeText12.setText(TimeUtils.dateToStr(list.get(4),"."));
        timeText13.setText(TimeUtils.dateToStr(list.get(5),"."));
        timeText14.setText(TimeUtils.dateToStr(list.get(6),"."));
    }


    public void onClick(TextView view){
        view.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                TextView text = (TextView)v;
                curTime.setText(getDate(text.getText().toString()));
                AnimationManager.Instance().DoScaleAction(centerBtn, 1.0f,0.95f,1.0f,0.95f,1000,-1, true);
            }
        });
    }
}
